package com.youku.plugins.videoinfo.view
{
   import flash.display.Sprite;
   import flash.text.TextField;
   import com.youku.baseUI.BasePlayerButton;
   import flash.display.MovieClip;
   import flash.text.TextFormat;
   import flash.events.MouseEvent;
   import flash.events.Event;
   import com.youku.utils.DrawUtil;
   import com.youku.utils.LayoutHelper;
   import com.youku.skin.YaheiFontManager;
   import com.youku.utils.AssetUtil;
   
   public class VideoInfoPanel extends Sprite
   {
      
      public function VideoInfoPanel() {
         super();
         this._background = this.getBackGround(this.VIDEOINFO_WIDTH,this.VIDEOINFO_HEIGHT);
         this._closeButton = AssetUtil.getStyleButton("P_CloseButton");
         AssetUtil.restoreButtonSize(this._closeButton);
         this._infoText = AssetUtil.getTextField();
         this._infoText.defaultTextFormat = this.INFO_TEXT_FORMAT;
         this._infoText.selectable = true;
         this._infoText.mouseEnabled = true;
         this._infoText.width = 230;
         this._infoText.height = 120;
         this._copyText = AssetUtil.getTextField();
         this._copyText.defaultTextFormat = this.INFO_TEXT_FORMAT;
         this._copyText.selectable = false;
         this._copyText.width = 50;
         this._copyText.height = 20;
         this._copyText.text = "复制";
         this._closeText = AssetUtil.getTextField();
         this._closeText.defaultTextFormat = this.INFO_TEXT_FORMAT;
         this._closeText.selectable = false;
         this._closeText.width = 50;
         this._closeText.height = 20;
         this._closeText.text = "关闭";
         this._checkIcon = AssetUtil.getAsset("T_Check_icon") as MovieClip;
         this.addChild(this._background);
         this.addChild(this._infoText);
         this.addChild(this._copyText);
         this.addChild(this._closeText);
         this.addChild(this._closeButton);
         this.addChild(this._checkIcon);
         this._checkIcon.visible = false;
         this._copyText.addEventListener(MouseEvent.CLICK,this.onCopyTextClick);
         this._closeButton.addEventListener(MouseEvent.CLICK,this.onCloseButtonClick);
         this._closeText.addEventListener(MouseEvent.CLICK,this.onCloseTextClick);
         this.updateLayout();
      }
      
      public static const EVENT_VIDEO_PANEL_CLOSE_TEXT:String = "event.closetext";
      
      public static const EVENT_VIDEO_PANEL_CLOSE_BUTTON:String = "event.closebutton";
      
      public static const EVENT_VIDEO_PANEL_COPY:String = "event.copy";
      
      protected var _background:Sprite;
      
      protected var _infoText:TextField;
      
      protected var _copyText:TextField;
      
      protected var _closeText:TextField;
      
      protected var _closeButton:BasePlayerButton;
      
      protected var _checkIcon:MovieClip;
      
      protected var _infoString:String = "";
      
      protected var _width:Number = 320;
      
      protected var _height:Number = 120;
      
      protected const VIDEOINFO_WIDTH:Number = 250;
      
      protected const VIDEOINFO_HEIGHT:Number = 155;
      
      protected const INFO_TEXT_FORMAT:TextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,12,16777215);
      
      private function onCloseButtonClick(param1:MouseEvent) : void {
         dispatchEvent(new Event(EVENT_VIDEO_PANEL_CLOSE_BUTTON));
      }
      
      private function onCloseTextClick(param1:MouseEvent) : void {
         dispatchEvent(new Event(EVENT_VIDEO_PANEL_CLOSE_TEXT));
      }
      
      private function onCopyTextClick(param1:MouseEvent) : void {
         this._checkIcon.visible = true;
         dispatchEvent(new Event(EVENT_VIDEO_PANEL_COPY));
      }
      
      private function getBackGround(param1:Number, param2:Number) : Sprite {
         var _loc3_:Sprite = new Sprite();
         var param1:Number = Math.round(param1);
         var param2:Number = Math.round(param2);
         _loc3_.addChild(DrawUtil.Line(0,0,param1,0,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(param1 - 1,1,param1 - 1,param2 - 1,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(param1,param2 - 1,0,param2 - 1,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Line(0,1,0,param2 - 1,8947848,0.8,1));
         _loc3_.addChild(DrawUtil.Rectangle(1,1,param1 - 2,param2 - 2,0,0.6,null,0));
         return _loc3_;
      }
      
      public function show() : void {
         this._checkIcon.visible = false;
      }
      
      public function setSize(param1:Number, param2:Number) : void {
         if(param1 < this.VIDEOINFO_WIDTH || param2 < this.VIDEOINFO_HEIGHT)
         {
            this.visible = false;
         }
         else
         {
            this.visible = true;
         }
         this._width = this.VIDEOINFO_WIDTH;
         this._height = this.VIDEOINFO_HEIGHT;
         if(this.contains(this._background))
         {
            removeChild(this._background);
         }
         this._background = this.getBackGround(this._width,this._height);
         addChildAt(this._background,0);
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._infoText.x = 10;
         this._infoText.y = 10;
         this._copyText.x = int((this._width - this._copyText.width - this._closeText.width - 10) / 2);
         this._copyText.y = 130;
         this._closeText.x = this._copyText.x + this._copyText.width + 10;
         this._closeText.y = 130;
         LayoutHelper.position(this._copyText,this._checkIcon,"left",4);
         this._checkIcon.y = 137;
         LayoutHelper.align(this._background,this._closeButton,"right",5);
         LayoutHelper.align(this._background,this._closeButton,"top",5);
      }
      
      public function updateInfo(param1:Object) : void {
         var _loc2_:* = "";
         _loc2_ = _loc2_ + ("视频分辨率 " + param1.videowidth + "x" + param1.videoheight);
         _loc2_ = _loc2_ + (" , 音量 " + param1.volume + "%\n");
         _loc2_ = _loc2_ + ("帧率 " + int(param1.fps));
         _loc2_ = _loc2_ + (" , 掉帧数 " + param1.dfps + "\n");
         _loc2_ = _loc2_ + ("正在下载第 " + param1.num + " 分片");
         _loc2_ = _loc2_ + (" , 速度 " + int(param1.speed / 1024) + " kbps\n");
         _loc2_ = _loc2_ + ("播放窗口尺寸 " + param1.width + "x" + param1.height + "\n");
         _loc2_ = _loc2_ + ("SVA: " + param1.svavaible + " " + "SVU: " + param1.svinuse + "\n");
         _loc2_ = _loc2_ + ("decode: " + param1.decode + "\n");
         this._infoString = _loc2_;
         this._infoText.text = _loc2_;
      }
      
      public function get infoString() : String {
         return this._infoString;
      }
   }
}
